import 'package:flutter/material.dart';
import 'package:flutter_shop/pages/cart/cart_tab_page/entity/cart_goods_data.dart';
import 'package:flutter_shop/pages/cart/cart_tab_page/provider/cart_provider.dart';
import 'package:flutter_shop/res/colors.dart';
import 'package:flutter_shop/res/dimens.dart';
import 'package:flutter_shop/res/styles.dart';
import 'package:flutter_shop/widget/water_click.dart';
import 'package:provider/provider.dart';

///购物车计数
class CartCounter extends StatelessWidget {
  final CartGoodsData item;

  CartCounter({Key key, this.item}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      width: 80,
      height: 25,
      decoration: BoxDecoration(
        border: Border.all(color: CommonColors.common_divide_line),
      ),
      child: Row(
        children: <Widget>[
          WaterClick(
            alignment: Alignment.center,
            width: 25,
            height: 25,
            decoration: BoxDecoration(
              border: Borders.right,
            ),
            onPressed: () {
              Provider.of<CartProvider>(context, listen: false).incrOrDecr(item.goodsId, false);
            },
            child: Text(
              "-",
              style: TextStyle(fontSize: CommonDimens.font_size_large, color: CommonColors.gray),
            ),
          ),
          Expanded(
            child: Container(
              height: 25,
              alignment: Alignment.center,
              child: Text("${item.count}"),
            ),
          ),
          WaterClick(
            alignment: Alignment.center,
            width: 25,
            height: 25,
            decoration: BoxDecoration(
              border: Borders.left,
            ),
            onPressed: () {
              Provider.of<CartProvider>(context, listen: false).incrOrDecr(item.goodsId, true);
            },
            child: Text(
              "+",
              style: TextStyle(fontSize: CommonDimens.font_size_large, color: CommonColors.gray),
            ),
          ),
        ],
      ),
    );
  }
}
